<template>
  <view class="viewProt">
    <view class="top">
      <view class="xinxi"> 个人信息 </view>
      <image class="profile" :src="data.avatar" mode="scaleToFill" />
      <view class="profileChenged"> 点击修改头像 </view>
    </view>
    <view class="info">
      <!-- <view class="box">
                <view class="list">
                    账号
                    <text class="data"></text>
                </view>
                <view class="list">
                    昵称
                    <text class="data">2</text
                        >
                </view>
                <view class="list">
                    性别
                    <text class="data">3</text>
                </view>
                <view class="list">
                    出生日期
                    <text class="data">4</text>
                </view>
                <view class="list">
                    城市
                    <text class="data">数据</text>
                </view>
                <view class="list">
                    职业
                    <text class="data">数据</text>
                </view>
            </view> -->
      <u--form labelPosition="left" :model="data" ref="form1">
        <u-form-item label="账号" borderBottom>
          <text>{{ data.account }}</text>
        </u-form-item>
        <u-form-item label="昵称" borderBottom>
          <u--input v-model="data.nickname" border="none"></u--input>
        </u-form-item>
        <u-form-item label="性别" prop="data.gender" borderBottom>
          <u-radio-group v-model="data.gender" placement="row">
            <u-radio label="男" value="男" name="男"></u-radio>
            <u-radio label="女" value="女" name="女"></u-radio>
          </u-radio-group>
        </u-form-item>
        <u-form-item label="出生日期" borderBottom>
          <u-datetime-picker
            @cancel="show = false"
            @confirm="confirmBtn"
            :show="show"
            v-model="data.birthday"
            mode="date"
          ></u-datetime-picker>
          <view @click="show = true">{{
            $u.timeFormat(this.data.birthday, "yyyy-mm-dd")
          }}</view>
        </u-form-item>
        <u-form-item label="城市" borderBottom>
          <view>{{ data.fullLocation }}</view>
        </u-form-item>
        <u-form-item label="职业" borderBottom>
          <u--input v-model="data.profession" border="none"></u--input>
        </u-form-item>
      </u--form>
    </view>
    <view class="saveBtn" @click="saveBtn"> 保存 </view>
  </view>
</template>
    
<script>
export default {
  data() {
    return {
      show: false,
      value1: "",
      data: {},
    };
  },
  methods: {
    timestampToTime(timestamp) {
      timestamp = timestamp ? timestamp : null;
      let date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      let Y = date.getFullYear() + "-";
      let M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      let D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";

      return Y + M + D;
    },

    async getinfo() {
      await uni.$u.http.get("/member/profile").then((res) => {
        console.log('获取个人信息', res);
        this.data = res.data.result;
      });
    },
    async baocun() {
      await uni.$u.http
        .put("/member/profile", { params: this.data })
        .then((res) => {
          console.log(res);
          if (res.data.code == "1") {
            console.log(111);
            // uni.navigateTo({
            //     url: '/pages/user/index?id=1',
            // })
            uni.redirectTo({
              url: `/pages/my/index?name=${res.data.result.nickname}&avatar=${res.data.result.avatar}`,
            });
          }
        });
    },
    confirmBtn() {
      // this.data.birthday = this.timestampToTime(this.data.birthday)
      this.show = false;
      console.log(this.data.birthday);
    },
    saveBtn() {
      this.baocun();
    },
  },
  onLoad: function (option) {
    this.getinfo();
    // console.log(option);
    // this.data = JSON.parse(decodeURIComponent(option.res));
    // console.log(this.data);

    // console.log(this.name);
  },
};
</script>
    
<style lang="scss" scoped>
.viewProt {
  height: 1335rpx;
  background: url(../../static/images/order_bg.png) no-repeat fixed top;
  background-size: 110%;
  background-color: #f4f4f4;

  // display: flex;
  // flex-direction: column;
  //   justify-content: center;
  .top {
    color: #fff;
    text-align: center;

    // .black{
    //    float: left;
    // }
    .xinxi {
      // float: left;
      padding: 30px 0;
      //    text-align: center;
    }

    .profile {
      height: 160rpx;
      width: 160rpx;
      border-radius: 50%;
    }

    .profileChenged {
      padding-top: 10rpx;
      font-size: 14px;
    }
  }

  .info {
    padding: 30rpx;

    .box {
      font-size: 14px;
      padding: 0 15px;
      height: 580rpx;
      // height: 100%;
      background-color: #fff;
      border-radius: 2%;

      .list {
        padding: 15px 0;
        border-bottom: #ddd solid 1px;

        &:nth-child(6) {
          border-bottom: 0;
        }

        .data {
          padding-left: 170rpx;
          //     &:nth-child(4){
          //         padding-left:100rpx ;
          // }
        }

        &:nth-child(4) .data {
          padding-left: 110rpx;
        }
      }
    }
  }

  .saveBtn {
    margin: 0 30rpx;
    height: 80rpx;
    background-color: #27ba9b;
    border-radius: 40rpx;
    text-align: center;
    line-height: 80rpx;
    color: white;
  }
}
</style>